package Reflect;

import java.lang.reflect.Method;
import java.util.Scanner;

public class ReflectDemo5 {

    public static void main(String[] args) throws Exception {
        Person p = new Person();
        p.sayHello();
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入一个类名(包含包)");
        String className = scanner.nextLine();
        System.out.println("请输入类中的一个方法名");
        String methodName = scanner.nextLine();

        Class aClass = Class.forName(className);
//        Method[] methods = aClass.getMethods();
//        for(Method method:methods){
//            System.out.println(method);
//        }
//        System.out.println(m);
        Method method = aClass.getMethod(methodName);
        Object obj1 = aClass.newInstance();
        method.invoke(obj1);


        Class<?> aClass1 = Class.forName("Reflect.Person");
        Object obj = aClass1.newInstance();
        Method method1 = aClass1.getMethod("say",String.class);
        Method method2 = aClass1.getMethod("test", Integer.class);
        Method method3 = aClass1.getMethod("say", String.class,int.class);
        method1.invoke(obj,"大家好");
        method2.invoke(obj,1);
        method3.invoke(obj,"赵家康",5);



    }
}
